package Preferences;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.Preference;
import android.util.Log;

import static android.content.Context.MODE_PRIVATE;

/**
 * @author zelonghu
 * @name test_all_without_network
 * @class name：Preferences
 * @class 用于存储系统的设置 to save the saving of the system
 * @time 2019/4/23 3:47 PM
 * @change
 * @chang time
 * @class describe
 */
public class Preferences extends Preference {
    private  Context context;

    public Preferences(Context context) {
        super(context);
        this.context = context;
    }

    /**
     * @author zelonghu
     * @time 2019/4/23  3:50 PM
     * @describe 存储
     */
    public void save(String name, String state){
        SharedPreferences p = context.getSharedPreferences("share", MODE_PRIVATE);
        SharedPreferences.Editor editor = p.edit();
        editor.putString("name",name);
        editor.putString("state",state);
        editor.commit();
    }

    /**
     * @author zelonghu
     * @time 2019/4/23  3:51 PM
     * @describe 存储是否开启后台监听 save the setting of the backgroundservice
     */
    public void saveBackgroundSensoringState(boolean state){
        String t = state?"t":"f";
        SharedPreferences p = context.getSharedPreferences("backgroundsetting", MODE_PRIVATE);
        SharedPreferences.Editor editor = p.edit();
        editor.putString("state",t);
        editor.commit();
    }

    /**
     * @author zelonghu
     * @time 2019/4/23  3:58 PM
     * @describe 返回是否开启监听设置 return the state of the background service .
     */
    public boolean checkBackgroundSensoringState(){
        SharedPreferences p = context.getSharedPreferences("backgroundsetting",MODE_PRIVATE);
        Log.i("test",p.getString("state",""));
        return p.getString("state","").equals("t")?true:false;
    }
}
